$(function(){
	var cookieName = $.cookie('username')
	if(cookieName){
		var header = '<img src="uploads/' + $.cookie('header') + '" onerror="this.src=\'images/user.png\'">'
		$('#user').empty().html(header+cookieName)
	}
	 $('.dropdown-menu li').last().click(function(){
    	$.removeCookie('username')
    	location.reload()
    })
	 $('#user').click(function(){
	 	if(!cookieName){
	 		$(this).removeAttr('data-toggle')
	 		location.href = '/signin'
	 	}
	 })
	 
	 $('#ask').click(function(){
	 	if(cookieName){
	 		location.href="/ask"
	 	}
	 })
	 
	 
	 $('form').submit(function(ev){
		ev.preventDefault()
		var data = new FormData(this)
		$.post({
			url:'/header',
			data:data,
			contentType:false,
			processData:false,
			success:function(data){
				if(data.code == 'success'){
					location.href='/'
				}else{
					alert(data.message)
				}
	        }
		})
	
	  })
	 
})
